package org.example.config;

import org.example.ResultMap;
import org.example.User;
import org.example.service.FeignService;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 熔断机制
 */
@Component
public class MyFeignClientFallbackFactory  implements FallbackFactory<FeignService> {
    @Override
    public FeignService create(Throwable cause) {
        return new FeignService() {
            @Override
            public ResultMap<User> getUserMap(String name, int age) {
                ResultMap resultMap = new ResultMap();
                resultMap.setCode(-1);
                resultMap.setMsg("熔断器启动");
                return resultMap;
            }
        };
    }
}
